
#include "Window.h"
#include "Image.h"
#include "Timer.h"
#include <fstream>
#include "Entity.h"
#include "SpriteComponent.h"
#include "CollisionSystem.h"
#include "SpriteSystem.h"

using namespace fe;
typedef Component Comp;

int main(int argv, char** argc)
{
    std::ofstream file("fps.txt");
    fe::Window window(640, 480, 32, "Racer", false);
    int fps = 0;
    fe::Timer timer;
    fe::Entity entity;
    SpriteSystem::getInst()->setWindow(&window);
    entity.addComponent(Comp::Sprite, new Sprite);
    entity.addComponent(Comp::Collision, new Collision);
    entity.getComponent<Sprite>(Comp::Sprite)->getImage().load("images/test.png");



    while(window.isOpen())
    {
        fps++;
        if(timer.getElapsedTime() >= 1.f)
        {
            file << fps << std::endl;
            fps = 0;
            timer.restart();
        }
        SDL_Event event;
        SDL_PollEvent(&event);
        if(event.type == SDL_QUIT)
            window.close();

        window.clear();
        SpriteSystem::getInst()->execute(); // executes the system
        CollisionSystem::getInst()->execute(); // executes the collision system
        window.display();
    }
    file.close();
    return 0;
}
